package com.ecoolex.discount.sales.api.graphql;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.lang.NonNull;

import com.ecoolex.discount.sales.entity.DiscountProductWithBLOBs;
import com.ecoolex.discount.sales.entity.MarketingProduct;
import com.ecoolex.discount.sales.pojo.QueryMarketingProductDTO;
import com.ecoolex.discount.sales.ws.DiscountProductService;
import com.ecoolex.discount.sales.ws.MarketingProductService;
import com.ecoolex.framework.common.pojo.Page;
import com.ecoolex.framework.common.pojo.Pagination;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module;
import com.ecoolex.framework.web.api.graphql2.annotation.QueryField;
import com.ecoolex.framework.web.api.graphql2.annotation.Source;
import com.ecoolex.framework.web.api.graphql2.annotation.TypeField;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module.Type;

@GraphQL2Module(type = Type.User,description = "产品营销")
public class MarketingProductGraphql {
	
	@Reference
	private MarketingProductService marketingProductService;
	
	@Reference
	private DiscountProductService discountProductService;
	
	@TypeField(type = MarketingProduct.class,field = "discountProduct",description = "折扣产品")
	public DiscountProductWithBLOBs discountProduct(@Source MarketingProduct source) {
		return discountProductService.getProductById(source.getProductId());
	}
	
	@QueryField(field = "marketingProduct",description = "产品营销详情")
	public MarketingProduct get(@NonNull Integer id) {
		return marketingProductService.getMarketingProduct(id);
	}
	
	@QueryField(field = "marketingProductList",description = "产品营销列表")
	public Pagination<MarketingProduct> query(@NonNull QueryMarketingProductDTO query,@NonNull Page page){
		return marketingProductService.queryMarketingProductForH5(query, page);
	}
}
